package com.dhcc.bpm.modules.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.system.entity.UserRole;
import com.dhcc.bpm.modules.system.service.IUserRoleService;
import com.dhcc.bpm.modules.system.vo.UserRoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName UserRoleController
 * @Description 用户角色关联表 控制器
 * @Author sjm
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@RestController
@AllArgsConstructor
@RequestMapping("bpm-system/userrole")
@Api(value = "", tags = "接口")
public class UserRoleController extends BladeController {

	private IUserRoleService userRoleService;

	/**
	 * @Description 详情
	 * @Author sjm
	 * @Date 10:11 2020/2/22 0022
	 * @param userRole
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.system.entity.UserRole>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入userRole")
	@ApiLog("详情")
	@Log(title = "查询详情", businessType = BusinessType.SELECT)
	public R<UserRole> detail(UserRole userRole) {
		UserRole detail = userRoleService.getOne(Condition.getQueryWrapper(userRole));
		return R.data(detail);
	}

	/**
	 * @Description 分页
	 * @Author sjm
	 * @Date 10:11 2020/2/22 0022
	 * @param userRole
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.system.entity.UserRole>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入userRole")
	@ApiLog("分页查询")
	@Log(title = "分页查询", businessType = BusinessType.SELECT)
	public R<IPage<UserRole>> list(UserRole userRole, Query query) {
		IPage<UserRole> pages = userRoleService.page(Condition.getPage(query), Condition.getQueryWrapper(userRole));
		return R.data(pages);
	}

	/**
	 * @Description 自定义分页
	 * @Author sjm
	 * @Date 10:11 2020/2/22 0022
	 * @param userRole
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.system.vo.UserRoleVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入userRole")
	@ApiLog("分页查询")
	@Log(title = "分页查询", businessType = BusinessType.SELECT)
	public R<IPage<UserRoleVO>> page(UserRoleVO userRole, Query query) {
		IPage<UserRoleVO> pages = userRoleService.selectUserRolePage(Condition.getPage(query), userRole);
		return R.data(pages);
	}

	/**
	 * @Description 新增
	 * @Author sjm
	 * @Date 10:11 2020/2/22 0022
	 * @param userRole
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入userRole")
	@ApiLog("新增")
	@Log(title = "新增", businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody UserRole userRole) {
		return R.status(userRoleService.save(userRole));
	}

	/**
	 * @Description 修改
	 * @Author sjm
	 * @Date 10:11 2020/2/22 0022
	 * @param userRole
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入userRole")
	@ApiLog("修改")
	@Log(title = "修改", businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody UserRole userRole) {
		return R.status(userRoleService.updateById(userRole));
	}

	/**
	 * @Description 新增或修改
	 * @Author sjm
	 * @Date 10:12 2020/2/22 0022
	 * @param userRole
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入userRole")
	@ApiLog("新增或修改")
	@Log(title = "新增或修改", businessType = BusinessType.UPDATE)
	public R submit(@Valid @RequestBody UserRole userRole) {
		return R.status(userRoleService.saveOrUpdate(userRole));
	}

	
	/**
	 * @Description 删除
	 * @Author sjm
	 * @Date 10:12 2020/2/22 0022
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	@ApiLog("删除")
	@Log(title = "删除", businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(userRoleService.removeByIds(Func.toLongList(ids)));
	}

	
}
